<template>
  <div>
    <el-table
      v-if="tableData"
      :data="
        tableData.filter(
          (data) =>
            !search || data.house.htitle.toLowerCase().includes(search.toLowerCase()) 
            || data.user.uname.toLowerCase().includes(search.toLowerCase())
        )
      "
      style="width: 100%"
    >
    <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
          <el-form-item label="房屋名称">
            <span>{{ props.row.house.htitle }}</span>
          </el-form-item>
          <el-form-item label="房屋地址">
            <span>{{ props.row.house.haddress }}</span>
          </el-form-item>
          <el-form-item label="户主名称">
            <span>{{ props.row.user.uname }}</span>
          </el-form-item>
          <el-form-item label="联系方式">
            <span>{{ props.row.user.uphone }}</span>
          </el-form-item>
          <el-form-item label="房租">
            <span>{{ props.row.house.hprice }}</span>
          </el-form-item>
          <el-form-item label="出租方式">
            <span>{{ props.row.house.hmode }}</span>
          </el-form-item>
          <el-form-item label="户型">
            <span>{{ props.row.house.htype }}</span>
          </el-form-item>
          <el-form-item label="发布日期">
            <span>{{ props.row.house.hreleasedate }}</span>
          </el-form-item>
          <el-form-item label="房屋面积">
            <span>{{ props.row.house.harea }}</span>
          </el-form-item>
          <el-form-item label="朝向">
            <span>{{ props.row.house.horientation }}</span>
          </el-form-item>
          <el-form-item label="电梯有无">
            <span>{{ props.row.house.helevator }}</span>
          </el-form-item>
          <el-form-item label="租期">
            <span>{{ props.row.house.hterm }}</span>
          </el-form-item>
          <el-form-item label="详细描述">
            <span>{{ props.row.house.hdescribe }}</span>
          </el-form-item>
          <el-form-item label="举报理由">
            <span>{{ props.row.report.reason }}</span>
          </el-form-item>
        </el-form>
      </template>
    </el-table-column>
      <el-table-column
        prop="house.htitle"
        label="房屋标题"
        width="180"
        sortable
      ></el-table-column>
      <el-table-column
        prop="user.uname"
        label="房主名"
        width="180"
        sortable
      ></el-table-column>
      <el-table-column
        prop="user.uphone"
        label="联系方式"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="admin.aname"
        label="审核管理员"
        width="180"
        sortable
      ></el-table-column>

      <el-table-column align="right">
        <template slot="header" slot-scope="{}">
          <el-input v-model="search" size="mini" placeholder="输入房屋名或房主名搜索" />
        </template>
        <template slot-scope="scope">
          <select-state @itemchange="itemChange" :truestate="scope.row.report.state"></select-state>
          <el-popconfirm
            confirm-button-text="好的"
            cancel-button-text="不用了"
            icon="el-icon-info"
            icon-color="red"
            title="确定要修改吗？"
            @onConfirm="handleEdit(scope.$index, scope.row)"
          >
            <el-button slot="reference" size="mini" type="danger"
              >修改</el-button
            >
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-row>
      <el-col :span="20" :offset="4">
        <el-pagination
          layout="prev, pager, next, jumper, total, sizes"
          background
          prev-text="prev"
          next-text="next"
          :page-size="size"
          :current-page="pageNow"
          :page-sizes="[5, 10, 15, 20]"
          @current-change="findPage"
          @size-change="findSize"
          :total="total"
        >
        </el-pagination>
      </el-col>
    </el-row>

    <el-button
      type="success"
      @click="saveAdminInfo"
      size="mini"
      style="margin-top: 10px"
      >添加</el-button
    >

    
  </div>
</template>

<script>
import selectState from '@/components/Select/selectState'
import { queryReportList } from "@/network/admin";
import {updateReport} from "@/network/admin";
export default {
  name: "reportInfo",
  components:{
    selectState
  },
  data() {
    return {
      tableData: [
        {},
      ],
      form: {},
      value:'',
      search: "",
      show: false,
      total: 0,
      size: 5,
      pageNow: 0,
    };
  },
  created() {
    queryReportList().then((res) => {
      // console.log(res);
      console.log(res);
      this.tableData = res.reports;
      this.total = res.total;
    });
  },
  methods: {
    itemChange(value){
      // console.log(value);
      this.value = value;
      // console.log(this.value);
    },
    // 处理
    findSize(size) {
      // console.log(size);
      this.size = size;
      this.findAllTableData((this.page - 1) * size, size);
    },
    // 处理分页的方法
    findPage(page) {
      console.log("page", page);
      this.pageNow = page;
      console.log((page - 1) * this.size);
      this.findAllTableData((page - 1) * this.size, this.size);
    },
    handleEdit(index, row) {
      row.report.aid = this.$store.state.user.name
      console.log(row.report);
      console.log(this.state)
      row.report.state = this.value;
      console.log("report",row.report.state);
      updateReport(row.report).then((res) => {
        if (res.status) {
          this.$message({
            message: res.msg,
            type: "success",
          });
          // 刷新数据
          console.log(this.pageNow, this.size);
          this.findAllTableData(this.pageNow, this.size);
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    
    findAllTableData(page, size) {
      console.log("findAllTableData", page, size);
      page = page ? page : this.pageNow;
      size = size ? size : this.size;
      // 记住传参
      queryExamineList(page, size).then((res) => {
        // console.log(res.admins);
        this.tableData = res.reports;
        this.total = res.total;
      });
    },
  },
};
</script>

<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>